package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.db.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @auther : 白月尘
 * @date : 14:37  2021/10/16
 */
@DubboService
public class UserApiImpl implements UserApi {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> queryWrapper=new QueryWrapper();
        queryWrapper.eq("mobile",mobile);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public long insert(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void setPhone(long userId,String phone) {
        User user=new User();
        user.setId(userId);
        user.setMobile(phone);
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long valueOf) {
        return userMapper.selectById(valueOf);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }
}
